﻿Imports Phila
Imports Phila.Sql
Imports Phila.CommonClasses

Public Class Tours
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            If Request.QueryString("tid") Is Nothing Then
                ltrTitle.Text = "<h2>Holiday Packages</h2>"
                'If dlTours.Items.Count = 0 Then
                '    lblMsg.Visible = True
                '    lblMsg.Text = "<p class=""message"">No Holiday Packages available</p>"
                'Else
                Fill_dtList(dlTours, "select * from ptn_Countries")
                'End If
                plTourList.Visible = True
                plTourDetails.Visible = False
            Else
                fillTour(Request.QueryString("tid"))
                plTourList.Visible = False
                plTourDetails.Visible = True
                Fill_dtList(dlImages, "select g.* from ptn_Gallery g inner join ptn_TourGallery tg on tg.GalleryId=g.Id where IsActive=1 and tg.TourId=" & Request.QueryString("tid"))
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub fillTour(ByVal ID As Integer)
        Dim strOutput As New StringBuilder
        'Dim strSql As String
        ' Dim txt As Array
        Dim dt As New DataTable

        'strSql = "SELECT [Id],[CategoryId],[ZoneId],[Name],[TourCode],[Days],[Nights],[Summary],[Description],[Include],[Exclude],[Cost],[MealType],"
        'strSql += "[Thumbnail],[GMap],[MetaTitle],[MetaKeywords],[MetaDescription],[IsFeatured],[IsPackage],[IsCruise],[IsSafari],[IsShortBreak],[IsActive],
        'strSql += "[Vieworder],[CreatedOn],[UpdatedOn],"
        'strSql += "(select Name from ptn_Category where Id=CategoryId) as CatName,"
        'strSql += "(select Name from ptn_Zones where Id=ZoneId) as ZoneName from ptn_tours"
        'strSql += "where IsActive=1 and id=@Id and ((@Type='P' and IsPackage=1) or (@Type='C' and IsCruise=1)"
        'strSql += "or (@Type='S' and IsSafari=1) or (@Type='SB' and IsShortBreak=1))"

        'dt = Fill_Table("exec fillTour " & Id & ", 'P'", "Tours")
        dt = Fill_Table("select * from ptn_Tours where Id=" & ID, "Tours")

        For Each dr As DataRow In dt.Rows
            'strOutput.Append("<h4><em>Cities Included:</em> " & dr.Item("Summary").ToString & "</h4>")
            'strOutput.Append("<div class=""description"">" & dr.Item("Description").ToString & "</div>")
            'ltrDescription.Text = strOutput.ToString
            ltrTitle.Text = "<h2>" & dr.Item("Name").ToString & " - " & dr.Item("TourCode").ToString & "<span>" & dr.Item("Days").ToString & " Days - " & dr.Item("Nights").ToString & " Nights</span></h2>"
            ltrSubTitle.Text = "<h4><em>Cities Included:</em> " & dr.Item("Summary").ToString & "</h4>"
            ltrDescription.Text += "<div class=""description"">" & dr.Item("Description").ToString & "</div>"


            ltrIncludes.Text = "<p><strong>The tour included:</strong></p>"
            ltrIncludes.Text += "<p>" & dr.Item("Include").ToString & "</p>"
            ltrIncludes.Text += "<p><strong>The tour excluded:</strong></p>"
            ltrIncludes.Text += "<p>" & dr.Item("Exclude").ToString & "</p>"

            Dim strClient As String
            If Session("UserId") Is Nothing Then
                strClient = "B2C"
            Else
                strClient = Session("Client")
            End If
            ltrCost.Text = getCost(ID, strClient)
        Next
    End Sub

    Private Function getCost(ByVal Id As Integer, ByVal Client As String)
        Dim strOutput As New StringBuilder
        Dim dtCost As DataTable
        Dim count As Integer = 0
        dtCost = Fill_Table("select top 1 [Id],[TourId],[Pax_1],[Pax_2],[Pax_3],[Pax_4],[Pax_5],[Pax_6],[Pax_7],[Pax_8],[Pax_9],[Pax_Child],[Single_Supp],CONVERT(VARCHAR(10), [StartDate], 103) [StartDate],CONVERT(VARCHAR(10), [EndDate], 103) [EndDate] from ptn_TourCost where Tourid=" & Id & " and ClientType='" & Client & "' and (getdate() between startdate and enddate) order by startdate desc, enddate desc", "TourCost")

        For Each drCost As DataRow In dtCost.Rows
            If drCost.Item("Pax_1").ToString <> 0 Then
                strOutput.Append("<div class=""costbox""><strong>1 Pax: </strong>" & formatPrice(drCost.Item("Pax_1").ToString) & "</div>")
            End If
            If drCost.Item("Pax_2").ToString <> 0 Then
                strOutput.Append("<div class=""costbox""><strong>2 Pax: </strong>" & formatPrice(drCost.Item("Pax_2").ToString) & "</div>")
            End If
            If drCost.Item("Pax_3").ToString <> 0 Then
                strOutput.Append("<div class=""costbox""><strong>3 Pax: </strong>" & formatPrice(drCost.Item("Pax_3").ToString) & "</div>")
            End If
            If drCost.Item("Pax_4").ToString <> 0 Then
                strOutput.Append("<div class=""costbox""><strong>4 pax: </strong>" & formatPrice(drCost.Item("Pax_4").ToString) & "</div>")
            End If
            If drCost.Item("Pax_5").ToString <> 0 Then
                strOutput.Append("<div class=""costbox""><strong>5 pax: </strong>" & formatPrice(drCost.Item("Pax_5").ToString) & "</div>")
            End If
            If drCost.Item("Pax_6").ToString <> 0 Then
                strOutput.Append("<div class=""costbox""><strong>6 pax: </strong>" & formatPrice(drCost.Item("Pax_6").ToString) & "</div>")
            End If
            If drCost.Item("Pax_7").ToString <> 0 Then
                strOutput.Append("<div class=""costbox""><strong>7 pax: </strong>" & formatPrice(drCost.Item("Pax_7").ToString) & "</div>")
            End If
            If drCost.Item("Pax_8").ToString <> 0 Then
                strOutput.Append("<div class=""costbox""><strong>8 pax: </strong>" & formatPrice(drCost.Item("Pax_8").ToString) & "</div>")
            End If
            If drCost.Item("Pax_9").ToString <> 0 Then
                strOutput.Append("<div class=""costbox""><strong>9 pax: </strong>" & formatPrice(drCost.Item("Pax_9").ToString) & "</div>")
            End If
            If drCost.Item("Single_Supp").ToString <> 0 Then
                strOutput.Append("<div class=""costbox""><strong>Single Supp: </strong>" & formatPrice(drCost.Item("Single_Supp").ToString) & "</div>")
            End If
            If drCost.Item("Pax_Child").ToString <> 0 Then
                strOutput.Append("<div class=""costbox""><strong>Child 0-10: </strong>" & formatPrice(drCost.Item("Pax_Child").ToString) & "</div>")
            End If
            strOutput.Append("<div class=""clear""></div><div class=""valid clearfix""><strong>Valid upto: </strong><span class=""date"">" & drCost.Item("EndDate").ToString & "</span></div>")
            count = count + 1
        Next
        If count = 0 Then

            Dim strSub As String
            If Not Request.QueryString("tId") Is Nothing Then
                Dim txt As Array
                txt = RetriveData("select Name, TourCode, Days, Nights from ptn_Tours where Id=" & Request.QueryString("tId"), 3)
                strSub = txt(0) & " - " & txt(1) & " (" & txt(2) & " Days/" & txt(3) & "Nights)"
            Else
                strSub = "Tour"
            End If

            strOutput.Append("<div class=""subhead"">Send a Request on <a href=""mailto:enquiry@philatourism.com?Subject=Request for " & strSub & """>enquiry@philatourism.com</a></div>")
        End If
        Return strOutput.ToString
    End Function


    Private Sub btnBook_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBook.Click
        If Not Request.QueryString("tid") Is Nothing Then
            Response.Redirect("BookTour.aspx?tid=" & Request.QueryString("tid"))
        End If
    End Sub
End Class